<?php
// +----------------------------------------------------------------------
// | Author: fulei  Email:365581323@qq.com
// +----------------------------------------------------------------------
namespace app\back\controller;
use think\Controller;
use think\Request;
use think\Db;
//评论管理
class Feedback extends Common
{   /*意见反馈*/
    public function index()
    {   
         $feedbackList = Db::name('user_feedback')->select();
         foreach($feedbackList as $k=>$val){
            $user_info=Db::name('user_info')->where(['uid'=>$val['uid']])->find();
            $feedbackList[$k]['nickname']=$user_info['nickname'];
         }
         //print_r($feedbackList);die;
          $this->assign('feedbackList',$feedbackList);
    	  //$this->assign('page',$page);
        return $this->fetch('Feedback/index');
    }
    //投诉列表
    public function complaints()
    {
    	// $id = input('id');
    	$data = Db::name('complaint')->select();
        foreach($data as $k=>$val){
            $nearby_name=Db::name('user_info')->where(['uid'=>$val['nearby_id']])->field('nickname')->find();
            $complain_name=Db::name('user_info')->where(['uid'=>$val['uid']])->field('nickname')->find();
            //被投诉者
            $data[$k]['nearby_name']=$nearby_name['nickname'];
            //投诉者
            $data[$k]['complain_name']=$complain_name['nickname'];
        }
       // print_r($data);die;
    	$this->assign('data',$data);
    	return $this->fetch('Feedback/complaints');
    }
    //保存数据
    public function save()
    {
    	$feed_id = input('feed_id');
    	$status = input('status');
    	$arr = array(
    		'feed_id' => $feed_id,
    		'status' => $status
    		);
    	$data = Db::name('feedback')->where('feed_id',$feed_id)->update($arr);
    	if($data){
    		$this->redirect('Feedback/index');
    	}else{
    		$this->redirect('Feedback/feed_deatil');
    	}
    }
    //删除数据
    public function del_feed()
    {
    	$feed_id = input('feed_id');
    	$data = Db::name('feedback')->where('feed_id',$feed_id)->delete();
    	if($data !==false){
    		return 1;
    	}else{
    		return 2;
    	}
    }
}